importScripts("https://g.alicdn.com/mylib/lp-workbox-cdn/3.6.3-2/workbox/workbox-sw.js");

workbox.core.setCacheNameDetails({ prefix: "pomodoro" });

workbox.skipWaiting();
workbox.clientsClaim();

workbox.precaching.suppressWarnings();
workbox.precaching.precacheAndRoute([
  {
    "url": "favicon.ico",
    "revision": "15aa342b61116634b58eaacd7e33cf1e"
  },
  {
    "url": "icons/192x192.png",
    "revision": "49812b2d41a91104f00cb63a085ce0c4"
  },
  {
    "url": "icons/512x512.png",
    "revision": "c1450d31e2e7b3b8209e3d8f371ebedf"
  },
  {
    "url": "launch/1242x2208.png",
    "revision": "0622045137256b28d409f2987a3eeaab"
  },
  {
    "url": "launch/1536x2048.png",
    "revision": "70467223fc8f6fe34651de55f8ec4226"
  },
  {
    "url": "launch/640x1136.png",
    "revision": "c6c807daabd2daadc8a970afbc378335"
  },
  {
    "url": "launch/750x1334.png",
    "revision": "bcb959155d4c1f8e445d1d77448a8712"
  },
  {
    "url": "static/css/1.28bc0e11.chunk.css",
    "revision": "8a561cfa9eac5b94952cdba4273a2979"
  },
  {
    "url": "static/css/main.5c2000c9.chunk.css",
    "revision": "43f093a784ded332ac3add3d027b9c79"
  },
  {
    "url": "static/js/1.644965c5.chunk.js",
    "revision": "b523ef671d688d6a8c76b6ae5eb0d0f5"
  },
  {
    "url": "static/js/main.92cb25f2.chunk.js",
    "revision": "6d734e9a3cfda62ed9f05877ad417863"
  },
  {
    "url": "static/js/runtime~main.4a686d48.js",
    "revision": "ff09bb0bd9dbcf5c637e384f220e8b80"
  },
  {
    "url": "static/media/about.87ac978e.svg",
    "revision": "87ac978e79ee22b2e95021eb9c035e8b"
  },
  {
    "url": "static/media/bg.e06d2bf1.svg",
    "revision": "e06d2bf116baa72bb92033e88df3b592"
  },
  {
    "url": "static/media/bg2.fa628b5e.svg",
    "revision": "fa628b5e930ca146ded4c1860a73a4f3"
  },
  {
    "url": "static/media/changliang.534348cb.svg",
    "revision": "534348cb86276fc5ece09f5bb3b2f05c"
  },
  {
    "url": "static/media/changliang2.e52b139f.svg",
    "revision": "e52b139f3098ec5d72ce3f58fcbed86c"
  },
  {
    "url": "static/media/clock.d01bbf21.mp3",
    "revision": "d01bbf21447a348044a2e0131b01d5f5"
  },
  {
    "url": "static/media/done.6bc57945.mp3",
    "revision": "6bc5794515ff2721df26c8a846455535"
  },
  {
    "url": "static/media/fanhui.c56dcaeb.svg",
    "revision": "c56dcaebbf02ae628d8cde32c4c48602"
  },
  {
    "url": "static/media/reload.4048e7e9.svg",
    "revision": "4048e7e95a7f16f13b0c300eebe5c84e"
  },
  {
    "url": "static/media/shengyin.5274603a.svg",
    "revision": "5274603a63145fd42493c0f69e1f5909"
  },
  {
    "url": "static/media/shengyin2.131cace0.svg",
    "revision": "131cace07850a5e81c25963baea913ad"
  },
  {
    "url": "static/media/v.07ba84ec.mp4",
    "revision": "07ba84ecf834bf174cad239540daa8cf"
  },
  {
    "url": "index.html",
    "revision": "9a43447a9a1144af97f32839d8bfb30"
  }
]);

workbox.routing.registerNavigationRoute("/pomodoro/index.html", {
  blacklist: [/^\/_/, /\/[^\/]+\.[^\/]+$/]
});

workbox.routing.registerRoute(
  /.*api\/pomodoro.json/,
  workbox.strategies.networkFirst({
    networkTimeoutSeconds: 3,
    fetchOptions: { cache: "no-store" },
    plugins: [new workbox.cacheableResponse.Plugin({ statuses: [0, 200] })]
  }),
  "GET"
);
workbox.routing.registerRoute(
  /.*.(jpg|png)/,
  workbox.strategies.cacheFirst({
    cacheName: "img-cache",
    plugins: [
      new workbox.cacheableResponse.Plugin({ statuses: [0, 200] }),
      new workbox.expiration.Plugin({
        maxEntries: 10,
        maxAgeSeconds: 432000,
        purgeOnQuotaError: false
      })
    ]
  }),
  "GET"
);

self.addEventListener("push", e => {
  const data = e.data.json();
  console.log(data);
  const options = {
    icon: data.icon,
    body: data.body
  };
  self.registration.showNotification(data.title, options);
});

self.addEventListener("notificationclick", e => {
  e.notification.close();
  self.clients.openWindow("/pomodoro"); // 如果有clienr的话，则focuse
});
